<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
            list-style:none;
        }
        div{
            width: 520px;
            height: 280px;
            margin: 100px auto;
            position: relative;
        }
        ul{
            width: 9999px;
            transform: translateX(0px);
        }
        ul li{
            float: left;
        }
        ol{
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
        }
        ol li{
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: white;
            float: left;
            margin: 0px 4px;
            cursor: pointer;
        }
        span{
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            background: red;
            cursor: pointer;
        }
        span:nth-of-type(1){
            left: 10px;
        }
        span:nth-of-type(2){
            right: -88px;
        }
        .yud{
            background: purple;
        }
    </style>
</head>
<body>
    <div id="box">
        <ul id="tup">
            <li><img src="images/p1.jpg" alt=""></li>
            <li><img src="images/p2.jpg" alt=""></li>
            <li><img src="images/p3.jpg" alt=""></li>
            <li><img src="images/p1.jpg" alt=""></li>
        </ul>
        <ol id="lol">
            <li class="yud"></li>
            <li></li>
            <li></li>
            <li></li>
        </ol>
        <span>◀</span>
        <span>▶</span>
        <script>
            var tup=document.getElementById('tup');
            var box=document.getElementById('box');
            var lol=document.getElementById('lol').children;
            var num=0;
            var timer;
            function fn(){
                    timer=setInterval(function(){
                    num++;
                    if(num>3){
                        num=0;
                    }
                    tup.style.transform='translate('+(-520*num)+'px)';
                    for(var i=0;i<lol.length;i++){
                        lol[i].className='';
                    }
                    lol[num].className='yud'
                },1000)
            }
            fn()
            box.onmouseenter=function(){
                clearInterval(timer)
            }
            box.onmouseleave=function(){
                fn()
            }
            for(var n=0;n<lol.length;n++){
                lol[n].sth=n;
                lol[n].onclick=function(){
                    for(var i=0;i<lol.length;i++){
                            list[i].className='';
                        }
                    this.className='yud'
                    num=this.sth
                    tup.style.transform='translate('+(-520*num)+'px)';
                }
            }
        </script>
    </div>
</body>
</html>